//
//  SubScrollView.m
//  Photograph
//
//  Created by TravelRound on 15/11/17.
//  Copyright © 2015年 TravelRound. All rights reserved.
//

#import "SubScrollView.h"

@implementation SubScrollView

- (instancetype)initWithFrame:(CGRect)frame index:(NSInteger)index
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviewsWithindex:index];
    }
    return self;
}


- (void)createSubviewsWithindex:(NSInteger)index
{
    
    self.minimumZoomScale = 1.0;
    self.maximumZoomScale = 10.0;
    self.delegate = self;
    
    NSString *fileName = nil;
    
    if (0 == index) {
        fileName = @"image19.jpg";
    } else if (20 == index) {
        fileName = @"image1.jpg";
    } else {
        fileName = [NSString stringWithFormat:@"image%ld.jpg", index];
    }
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    imageV.image = [UIImage imageNamed:fileName];
    [self addSubview:imageV];
    [imageV release];
    
}

- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    
//    if (self == scrollView) {
//        return self.subviews.firstObject;
//    } else {
//        return nil;
//    }
    
    return self == scrollView ? self.subviews.firstObject : nil;
    
}

@end
